# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/4 15:34
# 0. 导入需要的包和模块
from PyQt5.Qt import *
import sys

# 1. 创建一个应用程序对象
app = QApplication(sys.argv)
# 2. 控件的操作
# 2.1 创建控件
window = QWidget()
# 2.2 设置控件
window.setWindowTitle('')
window.resize(500, 500)


# *************排他性设置***************开始
# for i in range(0, 3):
# 	btn = QCheckBox(window)
# 	btn.setText('btn' + str(i))
# 	btn.move(50 * i, 50 * i)
# 	btn.setAutoExclusive(True)
# 	print(btn.autoExclusive())
# 	print(btn.isCheckable())
# 	# btn.setCheckable(False)
# # btn = QPushButton(window)
# # btn.setText('btn3')
# # btn.move(250,250)
# # btn.setCheckable(True)

# *************排他性设置***************结束

# *************按钮模拟点击***************开始
# btn = QPushButton(window)
# btn.setText('这是按钮')
# btn.move(200,200)
# btn.pressed.connect(lambda :print('点击了这个按钮'))
# # btn.click()
# # btn.animateClick(2000)
# btn2 = QPushButton(window)
# btn2.setText('按钮2')
# def test():
# 	# btn.click()
# 	btn.animateClick(2000)
# btn2.pressed.connect(test)

# *************按钮模拟点击***************结束

# *************设置有效区域***************开始
class Btn(QPushButton):
	def hitButton(self, point):
		# print(point)
		# if point.x() > self.width()/2:
		# 	return True
		# return False
		# 通过给定的坐标,计算与圆心的距离
		# 如果距离<半径 True
		center_x = self.width() / 2
		center_y = self.height() / 2

		hit_x = point.x()
		hit_y = point.y()
		import math
		dis = math.sqrt(math.pow(hit_x - center_x, 2) + math.pow(hit_y - center_y, 2))
		if dis < self.width() / 2:
			return True
		return False

	def paintEvent(self, evt):
		super().paintEvent(evt)
		painter = QPainter(self)
		painter.setPen(QPen(QColor(100,150,200),6))
		painter.drawEllipse(self.rect())

btn = Btn(window)
btn.setText('点击')
btn.move(100, 100)
btn.resize(200, 200)
# btn.setCheckable(True)
# btn.pressed.connect(lambda: print('按钮被按下了'))

# btn.released.connect(lambda :print('鼠标被释放了'))

# btn.clicked.connect(lambda value:print('按钮被点击了',value))

btn.toggled.connect(lambda value:print('按钮状态发生了改变',value))


# *************设置有效区域***************结束


# 2.3 展示控件
window.show()
# 3. 应用程序的执行,进入到消息循环
sys.exit(app.exec_())
